<template>
  <div class="member-order">
     <h2>订单列表</h2>
    <XtxTabs v-model="activeName" @tab-click="handleClick">
      <XtxTabsPanel
        v-for="item in orderStatus"
        :key="item.name"
        :name="item.name"
        :label="item.label"
      >
      </XtxTabsPanel>
    </XtxTabs>
     <!-- 订单列表 -->
    <div class="order-list">
    <OrderItem v-for="item in list" :key="item.id" :order="item" />
    <div class="empty" v-if="!list.length">...</div>
</div>
  </div>
</template>
<script>
import { reactive, ref, watch } from 'vue-demi'
import { orderStatus } from '@/constants/order.js'
import { reqFindOrderList } from '@/api/order'
import OrderItem from './components/order-item.vue'
export default {
  components: { OrderItem },
  name: 'MemberOrder',
  setup () {
    const activeName = ref('all')
    const handleClick = (val) => {
      reqParams.orderState = val.index
    }

    // 查询订单参数
    const reqParams = reactive({
      orderState: 0,
      page: 1,
      pageSize: 5
    })

    // 列表数据获取
    const list = ref([])
    watch(reqParams, () => {
      reqFindOrderList(reqParams).then(({ result }) => {
        console.log(result)
        // 🔔 列表的信息在 items 字段中
        list.value = result.items
      })
    }, { immediate: true })

    return { activeName, handleClick, orderStatus, list }
  }
}
</script>
<style scoped lang="less">
.order-list {
  background: #fff;
  padding: 20px;
}
.empty{
  min-height: 500px;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
